<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>16.5 Advanced topics | R Markdown 最佳指南</title>
  <meta name="description" content="The first official book authored by the core R Markdown developers that provides a comprehensive and accurate reference to the R Markdown ecosystem. With R Markdown, you can easily create reproducible data analysis reports, presentations, dashboards, interactive applications, books, dissertations, websites, and journal articles, while enjoying the simplicity of Markdown and the great power of R and other languages." />
  <meta name="generator" content="bookdown 0.18 and GitBook 2.6.7" />

  <meta property="og:title" content="16.5 Advanced topics | R Markdown 最佳指南" />
  <meta property="og:type" content="book" />
  <meta property="og:url" content="https://bookdown.org/yihui/rmarkdown/" />
  <meta property="og:image" content="https://bookdown.org/yihui/rmarkdown/images/cover.png" />
  <meta property="og:description" content="The first official book authored by the core R Markdown developers that provides a comprehensive and accurate reference to the R Markdown ecosystem. With R Markdown, you can easily create reproducible data analysis reports, presentations, dashboards, interactive applications, books, dissertations, websites, and journal articles, while enjoying the simplicity of Markdown and the great power of R and other languages." />
  <meta name="github-repo" content="rstudio/rmarkdown-book" />

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="16.5 Advanced topics | R Markdown 最佳指南" />
  
  <meta name="twitter:description" content="The first official book authored by the core R Markdown developers that provides a comprehensive and accurate reference to the R Markdown ecosystem. With R Markdown, you can easily create reproducible data analysis reports, presentations, dashboards, interactive applications, books, dissertations, websites, and journal articles, while enjoying the simplicity of Markdown and the great power of R and other languages." />
  <meta name="twitter:image" content="https://bookdown.org/yihui/rmarkdown/images/cover.png" />

<meta name="author" content="Yihui Xie, J. J. Allaire, Garrett Grolemund（著）" />
<meta name="author" content="王诗翔（译）" />


<meta name="date" content="2020-06-02" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="htmlwidgets-size.html"/>
<link rel="next" href="document-templates.html"/>
<script src="libs/jquery/jquery.min.js"></script>
<link href="libs/gitbook/css/style.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-clipboard.css" rel="stylesheet" />









<script src="libs/htmlwidgets/htmlwidgets.js"></script>
<script src="libs/sigma/sigma.min.js"></script>
<script src="libs/sigma/plugins/sigma.parsers.gexf.min.js"></script>
<script src="libs/sigma-binding/sigma.js"></script>


<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
  { position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
  { content: attr(data-line-number);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; pointer-events: all; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {  }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./">R Markdown: The Definitive Guide</a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>前言</a><ul>
<li class="chapter" data-level="" data-path="how-to-read-this-book.html"><a href="how-to-read-this-book.html"><i class="fa fa-check"></i>How to read this book</a></li>
<li class="chapter" data-level="" data-path="structure-of-the-book.html"><a href="structure-of-the-book.html"><i class="fa fa-check"></i>Structure of the book</a></li>
<li class="chapter" data-level="" data-path="software-info.html"><a href="software-info.html"><i class="fa fa-check"></i>Software information and conventions</a></li>
<li class="chapter" data-level="" data-path="acknowledgments.html"><a href="acknowledgments.html"><i class="fa fa-check"></i>Acknowledgments</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="author.html"><a href="author.html"><i class="fa fa-check"></i>About the Authors</a><ul>
<li class="chapter" data-level="" data-path="yihui-xie.html"><a href="yihui-xie.html"><i class="fa fa-check"></i>Yihui Xie</a></li>
<li class="chapter" data-level="" data-path="j-j-allaire.html"><a href="j-j-allaire.html"><i class="fa fa-check"></i>J.J. Allaire</a></li>
<li class="chapter" data-level="" data-path="garrett-grolemund.html"><a href="garrett-grolemund.html"><i class="fa fa-check"></i>Garrett Grolemund</a></li>
</ul></li>
<li class="part"><span><b>I Get Started</b></span></li>
<li class="chapter" data-level="1" data-path="installation.html"><a href="installation.html"><i class="fa fa-check"></i><b>1</b> Installation</a></li>
<li class="chapter" data-level="2" data-path="basics.html"><a href="basics.html"><i class="fa fa-check"></i><b>2</b> Basics</a><ul>
<li class="chapter" data-level="2.1" data-path="basics-examples.html"><a href="basics-examples.html"><i class="fa fa-check"></i><b>2.1</b> Example applications</a><ul>
<li class="chapter" data-level="2.1.1" data-path="basics-examples.html"><a href="basics-examples.html#airbnbs-knowledge-repository"><i class="fa fa-check"></i><b>2.1.1</b> Airbnb’s knowledge repository</a></li>
<li class="chapter" data-level="2.1.2" data-path="basics-examples.html"><a href="basics-examples.html#homework-assignments-on-rpubs"><i class="fa fa-check"></i><b>2.1.2</b> Homework assignments on RPubs</a></li>
<li class="chapter" data-level="2.1.3" data-path="basics-examples.html"><a href="basics-examples.html#personalized-mail"><i class="fa fa-check"></i><b>2.1.3</b> Personalized mail</a></li>
<li class="chapter" data-level="2.1.4" data-path="basics-examples.html"><a href="basics-examples.html#employer-health-benefits-survey"><i class="fa fa-check"></i><b>2.1.4</b> 2017 Employer Health Benefits Survey</a></li>
<li class="chapter" data-level="2.1.5" data-path="basics-examples.html"><a href="basics-examples.html#examples-journal"><i class="fa fa-check"></i><b>2.1.5</b> Journal articles</a></li>
<li class="chapter" data-level="2.1.6" data-path="basics-examples.html"><a href="basics-examples.html#dashboards-at-eelloo"><i class="fa fa-check"></i><b>2.1.6</b> Dashboards at eelloo</a></li>
<li class="chapter" data-level="2.1.7" data-path="basics-examples.html"><a href="basics-examples.html#examples-books"><i class="fa fa-check"></i><b>2.1.7</b> Books</a></li>
<li class="chapter" data-level="2.1.8" data-path="basics-examples.html"><a href="basics-examples.html#examples-websites"><i class="fa fa-check"></i><b>2.1.8</b> Websites</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="compile.html"><a href="compile.html"><i class="fa fa-check"></i><b>2.2</b> Compile an R Markdown document</a></li>
<li class="chapter" data-level="2.3" data-path="cheat-sheets.html"><a href="cheat-sheets.html"><i class="fa fa-check"></i><b>2.3</b> Cheat sheets</a></li>
<li class="chapter" data-level="2.4" data-path="output-formats.html"><a href="output-formats.html"><i class="fa fa-check"></i><b>2.4</b> Output formats</a></li>
<li class="chapter" data-level="2.5" data-path="markdown-syntax.html"><a href="markdown-syntax.html"><i class="fa fa-check"></i><b>2.5</b> Markdown syntax</a><ul>
<li class="chapter" data-level="2.5.1" data-path="markdown-syntax.html"><a href="markdown-syntax.html#inline-formatting"><i class="fa fa-check"></i><b>2.5.1</b> Inline formatting</a></li>
<li class="chapter" data-level="2.5.2" data-path="markdown-syntax.html"><a href="markdown-syntax.html#block-level-elements"><i class="fa fa-check"></i><b>2.5.2</b> Block-level elements</a></li>
<li class="chapter" data-level="2.5.3" data-path="markdown-syntax.html"><a href="markdown-syntax.html#math-expressions"><i class="fa fa-check"></i><b>2.5.3</b> Math expressions</a></li>
</ul></li>
<li class="chapter" data-level="2.6" data-path="r-code.html"><a href="r-code.html"><i class="fa fa-check"></i><b>2.6</b> R code chunks and inline R code</a><ul>
<li class="chapter" data-level="2.6.1" data-path="r-code.html"><a href="r-code.html#figures"><i class="fa fa-check"></i><b>2.6.1</b> Figures</a></li>
<li class="chapter" data-level="2.6.2" data-path="r-code.html"><a href="r-code.html#tables"><i class="fa fa-check"></i><b>2.6.2</b> Tables</a></li>
</ul></li>
<li class="chapter" data-level="2.7" data-path="language-engines.html"><a href="language-engines.html"><i class="fa fa-check"></i><b>2.7</b> Other language engines</a><ul>
<li class="chapter" data-level="2.7.1" data-path="language-engines.html"><a href="language-engines.html#python"><i class="fa fa-check"></i><b>2.7.1</b> Python</a></li>
<li class="chapter" data-level="2.7.2" data-path="language-engines.html"><a href="language-engines.html#shell-scripts"><i class="fa fa-check"></i><b>2.7.2</b> Shell scripts</a></li>
<li class="chapter" data-level="2.7.3" data-path="language-engines.html"><a href="language-engines.html#sql"><i class="fa fa-check"></i><b>2.7.3</b> SQL</a></li>
<li class="chapter" data-level="2.7.4" data-path="language-engines.html"><a href="language-engines.html#rcpp"><i class="fa fa-check"></i><b>2.7.4</b> Rcpp</a></li>
<li class="chapter" data-level="2.7.5" data-path="language-engines.html"><a href="language-engines.html#stan"><i class="fa fa-check"></i><b>2.7.5</b> Stan</a></li>
<li class="chapter" data-level="2.7.6" data-path="language-engines.html"><a href="language-engines.html#javascript-and-css"><i class="fa fa-check"></i><b>2.7.6</b> JavaScript and CSS</a></li>
<li class="chapter" data-level="2.7.7" data-path="language-engines.html"><a href="language-engines.html#julia"><i class="fa fa-check"></i><b>2.7.7</b> Julia</a></li>
<li class="chapter" data-level="2.7.8" data-path="language-engines.html"><a href="language-engines.html#c-and-fortran"><i class="fa fa-check"></i><b>2.7.8</b> C and Fortran</a></li>
</ul></li>
<li class="chapter" data-level="2.8" data-path="interactive-documents.html"><a href="interactive-documents.html"><i class="fa fa-check"></i><b>2.8</b> Interactive documents</a><ul>
<li class="chapter" data-level="2.8.1" data-path="interactive-documents.html"><a href="interactive-documents.html#intro-widgets"><i class="fa fa-check"></i><b>2.8.1</b> HTML widgets</a></li>
<li class="chapter" data-level="2.8.2" data-path="interactive-documents.html"><a href="interactive-documents.html#intro-shiny"><i class="fa fa-check"></i><b>2.8.2</b> Shiny documents</a></li>
</ul></li>
</ul></li>
<li class="part"><span><b>II Output Formats</b></span></li>
<li class="chapter" data-level="3" data-path="documents.html"><a href="documents.html"><i class="fa fa-check"></i><b>3</b> Documents</a><ul>
<li class="chapter" data-level="3.1" data-path="html-document.html"><a href="html-document.html"><i class="fa fa-check"></i><b>3.1</b> HTML document</a><ul>
<li class="chapter" data-level="3.1.1" data-path="html-document.html"><a href="html-document.html#table-of-contents"><i class="fa fa-check"></i><b>3.1.1</b> Table of contents</a></li>
<li class="chapter" data-level="3.1.2" data-path="html-document.html"><a href="html-document.html#section-numbering"><i class="fa fa-check"></i><b>3.1.2</b> Section numbering</a></li>
<li class="chapter" data-level="3.1.3" data-path="html-document.html"><a href="html-document.html#tabbed-sections"><i class="fa fa-check"></i><b>3.1.3</b> Tabbed sections</a></li>
<li class="chapter" data-level="3.1.4" data-path="html-document.html"><a href="html-document.html#appearance-and-style"><i class="fa fa-check"></i><b>3.1.4</b> Appearance and style</a></li>
<li class="chapter" data-level="3.1.5" data-path="html-document.html"><a href="html-document.html#figure-options"><i class="fa fa-check"></i><b>3.1.5</b> Figure options</a></li>
<li class="chapter" data-level="3.1.6" data-path="html-document.html"><a href="html-document.html#data-frame-printing"><i class="fa fa-check"></i><b>3.1.6</b> Data frame printing</a></li>
<li class="chapter" data-level="3.1.7" data-path="html-document.html"><a href="html-document.html#code-folding"><i class="fa fa-check"></i><b>3.1.7</b> Code folding</a></li>
<li class="chapter" data-level="3.1.8" data-path="html-document.html"><a href="html-document.html#mathjax-equations"><i class="fa fa-check"></i><b>3.1.8</b> MathJax equations</a></li>
<li class="chapter" data-level="3.1.9" data-path="html-document.html"><a href="html-document.html#document-dependencies"><i class="fa fa-check"></i><b>3.1.9</b> Document dependencies</a></li>
<li class="chapter" data-level="3.1.10" data-path="html-document.html"><a href="html-document.html#advanced-customization"><i class="fa fa-check"></i><b>3.1.10</b> Advanced customization</a></li>
<li class="chapter" data-level="3.1.11" data-path="html-document.html"><a href="html-document.html#shared-options"><i class="fa fa-check"></i><b>3.1.11</b> Shared options</a></li>
<li class="chapter" data-level="3.1.12" data-path="html-document.html"><a href="html-document.html#html-fragments"><i class="fa fa-check"></i><b>3.1.12</b> HTML fragments</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="notebook.html"><a href="notebook.html"><i class="fa fa-check"></i><b>3.2</b> Notebook</a><ul>
<li class="chapter" data-level="3.2.1" data-path="notebook.html"><a href="notebook.html#using-notebooks"><i class="fa fa-check"></i><b>3.2.1</b> Using Notebooks</a></li>
<li class="chapter" data-level="3.2.2" data-path="notebook.html"><a href="notebook.html#saving-and-sharing"><i class="fa fa-check"></i><b>3.2.2</b> Saving and sharing</a></li>
<li class="chapter" data-level="3.2.3" data-path="notebook.html"><a href="notebook.html#notebook-format"><i class="fa fa-check"></i><b>3.2.3</b> Notebook format</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="pdf-document.html"><a href="pdf-document.html"><i class="fa fa-check"></i><b>3.3</b> PDF document</a><ul>
<li class="chapter" data-level="3.3.1" data-path="pdf-document.html"><a href="pdf-document.html#table-of-contents-1"><i class="fa fa-check"></i><b>3.3.1</b> Table of contents</a></li>
<li class="chapter" data-level="3.3.2" data-path="pdf-document.html"><a href="pdf-document.html#figure-options-1"><i class="fa fa-check"></i><b>3.3.2</b> Figure options</a></li>
<li class="chapter" data-level="3.3.3" data-path="pdf-document.html"><a href="pdf-document.html#data-frame-printing-1"><i class="fa fa-check"></i><b>3.3.3</b> Data frame printing</a></li>
<li class="chapter" data-level="3.3.4" data-path="pdf-document.html"><a href="pdf-document.html#syntax-highlighting"><i class="fa fa-check"></i><b>3.3.4</b> Syntax highlighting</a></li>
<li class="chapter" data-level="3.3.5" data-path="pdf-document.html"><a href="pdf-document.html#latex-options"><i class="fa fa-check"></i><b>3.3.5</b> LaTeX options</a></li>
<li class="chapter" data-level="3.3.6" data-path="pdf-document.html"><a href="pdf-document.html#latex-packages-for-citations"><i class="fa fa-check"></i><b>3.3.6</b> LaTeX packages for citations</a></li>
<li class="chapter" data-level="3.3.7" data-path="pdf-document.html"><a href="pdf-document.html#advanced-customization-1"><i class="fa fa-check"></i><b>3.3.7</b> Advanced customization</a></li>
<li class="chapter" data-level="3.3.8" data-path="pdf-document.html"><a href="pdf-document.html#other-features"><i class="fa fa-check"></i><b>3.3.8</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="3.4" data-path="word-document.html"><a href="word-document.html"><i class="fa fa-check"></i><b>3.4</b> Word document</a><ul>
<li class="chapter" data-level="3.4.1" data-path="word-document.html"><a href="word-document.html#other-features-1"><i class="fa fa-check"></i><b>3.4.1</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="opendocument-text-document.html"><a href="opendocument-text-document.html"><i class="fa fa-check"></i><b>3.5</b> OpenDocument Text document</a><ul>
<li class="chapter" data-level="3.5.1" data-path="opendocument-text-document.html"><a href="opendocument-text-document.html#other-features-2"><i class="fa fa-check"></i><b>3.5.1</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="3.6" data-path="rich-text-format-document.html"><a href="rich-text-format-document.html"><i class="fa fa-check"></i><b>3.6</b> Rich Text Format document</a><ul>
<li class="chapter" data-level="3.6.1" data-path="rich-text-format-document.html"><a href="rich-text-format-document.html#other-features-3"><i class="fa fa-check"></i><b>3.6.1</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="3.7" data-path="markdown-document.html"><a href="markdown-document.html"><i class="fa fa-check"></i><b>3.7</b> Markdown document</a><ul>
<li class="chapter" data-level="3.7.1" data-path="markdown-document.html"><a href="markdown-document.html#markdown-variants"><i class="fa fa-check"></i><b>3.7.1</b> Markdown variants</a></li>
<li class="chapter" data-level="3.7.2" data-path="markdown-document.html"><a href="markdown-document.html#other-features-4"><i class="fa fa-check"></i><b>3.7.2</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="3.8" data-path="r-package-vignette.html"><a href="r-package-vignette.html"><i class="fa fa-check"></i><b>3.8</b> R package vignette</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="presentations.html"><a href="presentations.html"><i class="fa fa-check"></i><b>4</b> Presentations</a><ul>
<li class="chapter" data-level="4.1" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html"><i class="fa fa-check"></i><b>4.1</b> ioslides presentation</a><ul>
<li class="chapter" data-level="4.1.1" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#display-modes"><i class="fa fa-check"></i><b>4.1.1</b> Display modes</a></li>
<li class="chapter" data-level="4.1.2" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#incremental-bullets"><i class="fa fa-check"></i><b>4.1.2</b> Incremental bullets</a></li>
<li class="chapter" data-level="4.1.3" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#visual-appearance"><i class="fa fa-check"></i><b>4.1.3</b> Visual appearance</a></li>
<li class="chapter" data-level="4.1.4" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#code-highlighting"><i class="fa fa-check"></i><b>4.1.4</b> Code highlighting</a></li>
<li class="chapter" data-level="4.1.5" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#adding-a-logo"><i class="fa fa-check"></i><b>4.1.5</b> Adding a logo</a></li>
<li class="chapter" data-level="4.1.6" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#tables-1"><i class="fa fa-check"></i><b>4.1.6</b> Tables</a></li>
<li class="chapter" data-level="4.1.7" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#advanced-layout"><i class="fa fa-check"></i><b>4.1.7</b> Advanced layout</a></li>
<li class="chapter" data-level="4.1.8" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#text-color"><i class="fa fa-check"></i><b>4.1.8</b> Text color</a></li>
<li class="chapter" data-level="4.1.9" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#presenter-mode"><i class="fa fa-check"></i><b>4.1.9</b> Presenter mode</a></li>
<li class="chapter" data-level="4.1.10" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#printing-and-pdf-output"><i class="fa fa-check"></i><b>4.1.10</b> Printing and PDF output</a></li>
<li class="chapter" data-level="4.1.11" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#custom-templates-2"><i class="fa fa-check"></i><b>4.1.11</b> Custom templates</a></li>
<li class="chapter" data-level="4.1.12" data-path="ioslides-presentation.html"><a href="ioslides-presentation.html#other-features-5"><i class="fa fa-check"></i><b>4.1.12</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="slidy-presentation.html"><a href="slidy-presentation.html"><i class="fa fa-check"></i><b>4.2</b> Slidy presentation</a><ul>
<li class="chapter" data-level="4.2.1" data-path="slidy-presentation.html"><a href="slidy-presentation.html#display-modes-1"><i class="fa fa-check"></i><b>4.2.1</b> Display modes</a></li>
<li class="chapter" data-level="4.2.2" data-path="slidy-presentation.html"><a href="slidy-presentation.html#text-size"><i class="fa fa-check"></i><b>4.2.2</b> Text size</a></li>
<li class="chapter" data-level="4.2.3" data-path="slidy-presentation.html"><a href="slidy-presentation.html#footer-elements"><i class="fa fa-check"></i><b>4.2.3</b> Footer elements</a></li>
<li class="chapter" data-level="4.2.4" data-path="slidy-presentation.html"><a href="slidy-presentation.html#other-features-6"><i class="fa fa-check"></i><b>4.2.4</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="4.3" data-path="beamer-presentation.html"><a href="beamer-presentation.html"><i class="fa fa-check"></i><b>4.3</b> Beamer presentation</a><ul>
<li class="chapter" data-level="4.3.1" data-path="beamer-presentation.html"><a href="beamer-presentation.html#themes"><i class="fa fa-check"></i><b>4.3.1</b> Themes</a></li>
<li class="chapter" data-level="4.3.2" data-path="beamer-presentation.html"><a href="beamer-presentation.html#slide-level"><i class="fa fa-check"></i><b>4.3.2</b> Slide level</a></li>
<li class="chapter" data-level="4.3.3" data-path="beamer-presentation.html"><a href="beamer-presentation.html#other-features-7"><i class="fa fa-check"></i><b>4.3.3</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="4.4" data-path="powerpoint-presentation.html"><a href="powerpoint-presentation.html"><i class="fa fa-check"></i><b>4.4</b> PowerPoint presentation</a><ul>
<li class="chapter" data-level="4.4.1" data-path="powerpoint-presentation.html"><a href="powerpoint-presentation.html#ppt-templates"><i class="fa fa-check"></i><b>4.4.1</b> Custom templates</a></li>
<li class="chapter" data-level="4.4.2" data-path="powerpoint-presentation.html"><a href="powerpoint-presentation.html#other-features-8"><i class="fa fa-check"></i><b>4.4.2</b> Other features</a></li>
</ul></li>
</ul></li>
<li class="part"><span><b>III Extensions</b></span></li>
<li class="chapter" data-level="5" data-path="dashboards.html"><a href="dashboards.html"><i class="fa fa-check"></i><b>5</b> Dashboards</a><ul>
<li class="chapter" data-level="5.1" data-path="layout.html"><a href="layout.html"><i class="fa fa-check"></i><b>5.1</b> Layout</a><ul>
<li class="chapter" data-level="5.1.1" data-path="layout.html"><a href="layout.html#row-based-layouts"><i class="fa fa-check"></i><b>5.1.1</b> Row-based layouts</a></li>
<li class="chapter" data-level="5.1.2" data-path="layout.html"><a href="layout.html#attributes-on-sections"><i class="fa fa-check"></i><b>5.1.2</b> Attributes on sections</a></li>
<li class="chapter" data-level="5.1.3" data-path="layout.html"><a href="layout.html#multiple-pages"><i class="fa fa-check"></i><b>5.1.3</b> Multiple pages</a></li>
<li class="chapter" data-level="5.1.4" data-path="layout.html"><a href="layout.html#story-boards"><i class="fa fa-check"></i><b>5.1.4</b> Story boards</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="dashboard-components.html"><a href="dashboard-components.html"><i class="fa fa-check"></i><b>5.2</b> Components</a><ul>
<li class="chapter" data-level="5.2.1" data-path="dashboard-components.html"><a href="dashboard-components.html#value-boxes"><i class="fa fa-check"></i><b>5.2.1</b> Value boxes</a></li>
<li class="chapter" data-level="5.2.2" data-path="dashboard-components.html"><a href="dashboard-components.html#gauges"><i class="fa fa-check"></i><b>5.2.2</b> Gauges</a></li>
<li class="chapter" data-level="5.2.3" data-path="dashboard-components.html"><a href="dashboard-components.html#text-annotations"><i class="fa fa-check"></i><b>5.2.3</b> Text annotations</a></li>
<li class="chapter" data-level="5.2.4" data-path="dashboard-components.html"><a href="dashboard-components.html#navigation-bar"><i class="fa fa-check"></i><b>5.2.4</b> Navigation bar</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="shiny.html"><a href="shiny.html"><i class="fa fa-check"></i><b>5.3</b> Shiny</a><ul>
<li class="chapter" data-level="5.3.1" data-path="shiny.html"><a href="shiny.html#getting-started"><i class="fa fa-check"></i><b>5.3.1</b> Getting started</a></li>
<li class="chapter" data-level="5.3.2" data-path="shiny.html"><a href="shiny.html#a-shiny-dashboard-example"><i class="fa fa-check"></i><b>5.3.2</b> A Shiny dashboard example</a></li>
<li class="chapter" data-level="5.3.3" data-path="shiny.html"><a href="shiny.html#input-sidebar"><i class="fa fa-check"></i><b>5.3.3</b> Input sidebar</a></li>
<li class="chapter" data-level="5.3.4" data-path="shiny.html"><a href="shiny.html#learning-more"><i class="fa fa-check"></i><b>5.3.4</b> Learning more</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="6" data-path="tufte-handouts.html"><a href="tufte-handouts.html"><i class="fa fa-check"></i><b>6</b> Tufte Handouts</a><ul>
<li class="chapter" data-level="6.1" data-path="tufte-headings.html"><a href="tufte-headings.html"><i class="fa fa-check"></i><b>6.1</b> Headings</a></li>
<li class="chapter" data-level="6.2" data-path="tufte-figures.html"><a href="tufte-figures.html"><i class="fa fa-check"></i><b>6.2</b> Figures</a><ul>
<li class="chapter" data-level="6.2.1" data-path="tufte-figures.html"><a href="tufte-figures.html#margin-figures"><i class="fa fa-check"></i><b>6.2.1</b> Margin figures</a></li>
<li class="chapter" data-level="6.2.2" data-path="tufte-figures.html"><a href="tufte-figures.html#arbitrary-margin-content"><i class="fa fa-check"></i><b>6.2.2</b> Arbitrary margin content</a></li>
<li class="chapter" data-level="6.2.3" data-path="tufte-figures.html"><a href="tufte-figures.html#full-width-figures"><i class="fa fa-check"></i><b>6.2.3</b> Full-width figures</a></li>
<li class="chapter" data-level="6.2.4" data-path="tufte-figures.html"><a href="tufte-figures.html#main-column-figures"><i class="fa fa-check"></i><b>6.2.4</b> Main column figures</a></li>
</ul></li>
<li class="chapter" data-level="6.3" data-path="tufte-sidenotes.html"><a href="tufte-sidenotes.html"><i class="fa fa-check"></i><b>6.3</b> Sidenotes</a></li>
<li class="chapter" data-level="6.4" data-path="tufte-references.html"><a href="tufte-references.html"><i class="fa fa-check"></i><b>6.4</b> References</a></li>
<li class="chapter" data-level="6.5" data-path="tufte-tables.html"><a href="tufte-tables.html"><i class="fa fa-check"></i><b>6.5</b> Tables</a></li>
<li class="chapter" data-level="6.6" data-path="tufte-quotes.html"><a href="tufte-quotes.html"><i class="fa fa-check"></i><b>6.6</b> Block quotes</a></li>
<li class="chapter" data-level="6.7" data-path="tufte-responsiveness.html"><a href="tufte-responsiveness.html"><i class="fa fa-check"></i><b>6.7</b> Responsiveness</a></li>
<li class="chapter" data-level="6.8" data-path="tufte-sans.html"><a href="tufte-sans.html"><i class="fa fa-check"></i><b>6.8</b> Sans-serif fonts and epigraphs</a></li>
<li class="chapter" data-level="6.9" data-path="tufte-css.html"><a href="tufte-css.html"><i class="fa fa-check"></i><b>6.9</b> Customize CSS styles</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="xaringan.html"><a href="xaringan.html"><i class="fa fa-check"></i><b>7</b> xaringan Presentations</a><ul>
<li class="chapter" data-level="7.1" data-path="xaringan-start.html"><a href="xaringan-start.html"><i class="fa fa-check"></i><b>7.1</b> Get started</a></li>
<li class="chapter" data-level="7.2" data-path="xaringan-key.html"><a href="xaringan-key.html"><i class="fa fa-check"></i><b>7.2</b> Keyboard shortcuts</a></li>
<li class="chapter" data-level="7.3" data-path="xaringan-format.html"><a href="xaringan-format.html"><i class="fa fa-check"></i><b>7.3</b> Slide formatting</a><ul>
<li class="chapter" data-level="7.3.1" data-path="xaringan-format.html"><a href="xaringan-format.html#slides-and-properties"><i class="fa fa-check"></i><b>7.3.1</b> Slides and properties</a></li>
<li class="chapter" data-level="7.3.2" data-path="xaringan-format.html"><a href="xaringan-format.html#the-title-slide"><i class="fa fa-check"></i><b>7.3.2</b> The title slide</a></li>
<li class="chapter" data-level="7.3.3" data-path="xaringan-format.html"><a href="xaringan-format.html#content-classes"><i class="fa fa-check"></i><b>7.3.3</b> Content classes</a></li>
<li class="chapter" data-level="7.3.4" data-path="xaringan-format.html"><a href="xaringan-format.html#incremental-slides"><i class="fa fa-check"></i><b>7.3.4</b> Incremental slides</a></li>
<li class="chapter" data-level="7.3.5" data-path="xaringan-format.html"><a href="xaringan-format.html#xaringan-notes"><i class="fa fa-check"></i><b>7.3.5</b> Presenter notes</a></li>
<li class="chapter" data-level="7.3.6" data-path="xaringan-format.html"><a href="xaringan-format.html#yolo-true"><i class="fa fa-check"></i><b>7.3.6</b> yolo: true</a></li>
</ul></li>
<li class="chapter" data-level="7.4" data-path="xaringan-preview.html"><a href="xaringan-preview.html"><i class="fa fa-check"></i><b>7.4</b> Build and preview slides</a></li>
<li class="chapter" data-level="7.5" data-path="css-and-themes.html"><a href="css-and-themes.html"><i class="fa fa-check"></i><b>7.5</b> CSS and themes</a></li>
<li class="chapter" data-level="7.6" data-path="some-tips.html"><a href="some-tips.html"><i class="fa fa-check"></i><b>7.6</b> Some tips</a><ul>
<li class="chapter" data-level="7.6.1" data-path="some-tips.html"><a href="some-tips.html#autoplay-slides"><i class="fa fa-check"></i><b>7.6.1</b> Autoplay slides</a></li>
<li class="chapter" data-level="7.6.2" data-path="some-tips.html"><a href="some-tips.html#countdown-timer"><i class="fa fa-check"></i><b>7.6.2</b> Countdown timer</a></li>
<li class="chapter" data-level="7.6.3" data-path="some-tips.html"><a href="some-tips.html#highlight-code-lines"><i class="fa fa-check"></i><b>7.6.3</b> Highlight code lines</a></li>
<li class="chapter" data-level="7.6.4" data-path="some-tips.html"><a href="some-tips.html#working-offline"><i class="fa fa-check"></i><b>7.6.4</b> Working offline</a></li>
<li class="chapter" data-level="7.6.5" data-path="some-tips.html"><a href="some-tips.html#macros"><i class="fa fa-check"></i><b>7.6.5</b> Macros</a></li>
<li class="chapter" data-level="7.6.6" data-path="some-tips.html"><a href="some-tips.html#disadvantages"><i class="fa fa-check"></i><b>7.6.6</b> Disadvantages</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="8" data-path="revealjs.html"><a href="revealjs.html"><i class="fa fa-check"></i><b>8</b> reveal.js Presentations</a><ul>
<li class="chapter" data-level="8.1" data-path="display-modes-2.html"><a href="display-modes-2.html"><i class="fa fa-check"></i><b>8.1</b> Display modes</a></li>
<li class="chapter" data-level="8.2" data-path="appearance-and-style-1.html"><a href="appearance-and-style-1.html"><i class="fa fa-check"></i><b>8.2</b> Appearance and style</a><ul>
<li class="chapter" data-level="8.2.1" data-path="appearance-and-style-1.html"><a href="appearance-and-style-1.html#smaller-text"><i class="fa fa-check"></i><b>8.2.1</b> Smaller text</a></li>
</ul></li>
<li class="chapter" data-level="8.3" data-path="slide-transitions.html"><a href="slide-transitions.html"><i class="fa fa-check"></i><b>8.3</b> Slide transitions</a></li>
<li class="chapter" data-level="8.4" data-path="slide-backgrounds.html"><a href="slide-backgrounds.html"><i class="fa fa-check"></i><b>8.4</b> Slide backgrounds</a></li>
<li class="chapter" data-level="8.5" data-path="d-presentations.html"><a href="d-presentations.html"><i class="fa fa-check"></i><b>8.5</b> 2-D presentations</a></li>
<li class="chapter" data-level="8.6" data-path="custom-css-1.html"><a href="custom-css-1.html"><i class="fa fa-check"></i><b>8.6</b> Custom CSS</a><ul>
<li class="chapter" data-level="8.6.1" data-path="custom-css-1.html"><a href="custom-css-1.html#slide-ids-and-classes"><i class="fa fa-check"></i><b>8.6.1</b> Slide IDs and classes</a></li>
<li class="chapter" data-level="8.6.2" data-path="custom-css-1.html"><a href="custom-css-1.html#styling-text-spans"><i class="fa fa-check"></i><b>8.6.2</b> Styling text spans</a></li>
</ul></li>
<li class="chapter" data-level="8.7" data-path="reveal-js-options.html"><a href="reveal-js-options.html"><i class="fa fa-check"></i><b>8.7</b> reveal.js options</a></li>
<li class="chapter" data-level="8.8" data-path="reveal-js-plugins.html"><a href="reveal-js-plugins.html"><i class="fa fa-check"></i><b>8.8</b> reveal.js plugins</a></li>
<li class="chapter" data-level="8.9" data-path="other-features-9.html"><a href="other-features-9.html"><i class="fa fa-check"></i><b>8.9</b> Other features</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="community.html"><a href="community.html"><i class="fa fa-check"></i><b>9</b> Community Formats</a><ul>
<li class="chapter" data-level="9.1" data-path="prettydoc.html"><a href="prettydoc.html"><i class="fa fa-check"></i><b>9.1</b> Lightweight Pretty HTML Documents</a><ul>
<li class="chapter" data-level="9.1.1" data-path="prettydoc.html"><a href="prettydoc.html#prettydoc-usage"><i class="fa fa-check"></i><b>9.1.1</b> Usage</a></li>
<li class="chapter" data-level="9.1.2" data-path="prettydoc.html"><a href="prettydoc.html#prettydoc-vignettes"><i class="fa fa-check"></i><b>9.1.2</b> Package vignettes</a></li>
</ul></li>
<li class="chapter" data-level="9.2" data-path="rmdformats.html"><a href="rmdformats.html"><i class="fa fa-check"></i><b>9.2</b> The rmdformats package</a></li>
<li class="chapter" data-level="9.3" data-path="shower-presentations.html"><a href="shower-presentations.html"><i class="fa fa-check"></i><b>9.3</b> Shower presentations</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="websites.html"><a href="websites.html"><i class="fa fa-check"></i><b>10</b> Websites</a><ul>
<li class="chapter" data-level="10.1" data-path="blogdown-start.html"><a href="blogdown-start.html"><i class="fa fa-check"></i><b>10.1</b> Get started</a></li>
<li class="chapter" data-level="10.2" data-path="blogdown-directory.html"><a href="blogdown-directory.html"><i class="fa fa-check"></i><b>10.2</b> The directory structure</a></li>
<li class="chapter" data-level="10.3" data-path="blogdown-deploy.html"><a href="blogdown-deploy.html"><i class="fa fa-check"></i><b>10.3</b> Deployment</a></li>
<li class="chapter" data-level="10.4" data-path="blogdown-other.html"><a href="blogdown-other.html"><i class="fa fa-check"></i><b>10.4</b> Other site generators</a></li>
<li class="chapter" data-level="10.5" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html"><i class="fa fa-check"></i><b>10.5</b> rmarkdown’s site generator</a><ul>
<li class="chapter" data-level="10.5.1" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#a-simple-example"><i class="fa fa-check"></i><b>10.5.1</b> A simple example</a></li>
<li class="chapter" data-level="10.5.2" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#site-authoring"><i class="fa fa-check"></i><b>10.5.2</b> Site authoring</a></li>
<li class="chapter" data-level="10.5.3" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#common-elements"><i class="fa fa-check"></i><b>10.5.3</b> Common elements</a></li>
<li class="chapter" data-level="10.5.4" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#site-navigation"><i class="fa fa-check"></i><b>10.5.4</b> Site navigation</a></li>
<li class="chapter" data-level="10.5.5" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#html-generation"><i class="fa fa-check"></i><b>10.5.5</b> HTML generation</a></li>
<li class="chapter" data-level="10.5.6" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#site-configuration"><i class="fa fa-check"></i><b>10.5.6</b> Site configuration</a></li>
<li class="chapter" data-level="10.5.7" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#publishing-websites"><i class="fa fa-check"></i><b>10.5.7</b> Publishing websites</a></li>
<li class="chapter" data-level="10.5.8" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#additional-examples"><i class="fa fa-check"></i><b>10.5.8</b> Additional examples</a></li>
<li class="chapter" data-level="10.5.9" data-path="rmarkdown-site.html"><a href="rmarkdown-site.html#custom-site-generators"><i class="fa fa-check"></i><b>10.5.9</b> Custom site generators</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="11" data-path="pkgdown.html"><a href="pkgdown.html"><i class="fa fa-check"></i><b>11</b> HTML Documentation for R Packages</a><ul>
<li class="chapter" data-level="11.1" data-path="pkgdown-start.html"><a href="pkgdown-start.html"><i class="fa fa-check"></i><b>11.1</b> Get started</a></li>
<li class="chapter" data-level="11.2" data-path="pkgdown-components.html"><a href="pkgdown-components.html"><i class="fa fa-check"></i><b>11.2</b> Components</a><ul>
<li class="chapter" data-level="11.2.1" data-path="pkgdown-components.html"><a href="pkgdown-components.html#home-page"><i class="fa fa-check"></i><b>11.2.1</b> Home page</a></li>
<li class="chapter" data-level="11.2.2" data-path="pkgdown-components.html"><a href="pkgdown-components.html#function-reference"><i class="fa fa-check"></i><b>11.2.2</b> Function reference</a></li>
<li class="chapter" data-level="11.2.3" data-path="pkgdown-components.html"><a href="pkgdown-components.html#articles"><i class="fa fa-check"></i><b>11.2.3</b> Articles</a></li>
<li class="chapter" data-level="11.2.4" data-path="pkgdown-components.html"><a href="pkgdown-components.html#news"><i class="fa fa-check"></i><b>11.2.4</b> News</a></li>
<li class="chapter" data-level="11.2.5" data-path="pkgdown-components.html"><a href="pkgdown-components.html#navigation-bar-1"><i class="fa fa-check"></i><b>11.2.5</b> Navigation bar</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="12" data-path="books.html"><a href="books.html"><i class="fa fa-check"></i><b>12</b> Books</a><ul>
<li class="chapter" data-level="12.1" data-path="bookdown-start.html"><a href="bookdown-start.html"><i class="fa fa-check"></i><b>12.1</b> Get started</a></li>
<li class="chapter" data-level="12.2" data-path="bookdown-project.html"><a href="bookdown-project.html"><i class="fa fa-check"></i><b>12.2</b> Project structure</a><ul>
<li class="chapter" data-level="12.2.1" data-path="bookdown-project.html"><a href="bookdown-project.html#index-file"><i class="fa fa-check"></i><b>12.2.1</b> Index file</a></li>
<li class="chapter" data-level="12.2.2" data-path="bookdown-project.html"><a href="bookdown-project.html#rmd-files"><i class="fa fa-check"></i><b>12.2.2</b> Rmd files</a></li>
<li class="chapter" data-level="12.2.3" data-path="bookdown-project.html"><a href="bookdown-project.html#bookdown.yml"><i class="fa fa-check"></i><b>12.2.3</b> <code>_bookdown.yml</code></a></li>
<li class="chapter" data-level="12.2.4" data-path="bookdown-project.html"><a href="bookdown-project.html#output.yml"><i class="fa fa-check"></i><b>12.2.4</b> <code>_output.yml</code></a></li>
</ul></li>
<li class="chapter" data-level="12.3" data-path="bookdown-markdown.html"><a href="bookdown-markdown.html"><i class="fa fa-check"></i><b>12.3</b> Markdown extensions</a><ul>
<li class="chapter" data-level="12.3.1" data-path="bookdown-markdown.html"><a href="bookdown-markdown.html#equations"><i class="fa fa-check"></i><b>12.3.1</b> Number and reference equations</a></li>
<li class="chapter" data-level="12.3.2" data-path="bookdown-markdown.html"><a href="bookdown-markdown.html#theorems"><i class="fa fa-check"></i><b>12.3.2</b> Theorems and proofs</a></li>
<li class="chapter" data-level="12.3.3" data-path="bookdown-markdown.html"><a href="bookdown-markdown.html#special-headers"><i class="fa fa-check"></i><b>12.3.3</b> Special headers</a></li>
<li class="chapter" data-level="12.3.4" data-path="bookdown-markdown.html"><a href="bookdown-markdown.html#text-references"><i class="fa fa-check"></i><b>12.3.4</b> Text references</a></li>
<li class="chapter" data-level="12.3.5" data-path="bookdown-markdown.html"><a href="bookdown-markdown.html#cross-referencing"><i class="fa fa-check"></i><b>12.3.5</b> Cross referencing</a></li>
</ul></li>
<li class="chapter" data-level="12.4" data-path="bookdown-output.html"><a href="bookdown-output.html"><i class="fa fa-check"></i><b>12.4</b> Output Formats</a><ul>
<li class="chapter" data-level="12.4.1" data-path="bookdown-output.html"><a href="bookdown-output.html#html"><i class="fa fa-check"></i><b>12.4.1</b> HTML</a></li>
<li class="chapter" data-level="12.4.2" data-path="bookdown-output.html"><a href="bookdown-output.html#latexpdf"><i class="fa fa-check"></i><b>12.4.2</b> LaTeX/PDF</a></li>
<li class="chapter" data-level="12.4.3" data-path="bookdown-output.html"><a href="bookdown-output.html#e-books"><i class="fa fa-check"></i><b>12.4.3</b> E-books</a></li>
<li class="chapter" data-level="12.4.4" data-path="bookdown-output.html"><a href="bookdown-output.html#a-single-document"><i class="fa fa-check"></i><b>12.4.4</b> A single document</a></li>
</ul></li>
<li class="chapter" data-level="12.5" data-path="bookdown-edit.html"><a href="bookdown-edit.html"><i class="fa fa-check"></i><b>12.5</b> Editing</a><ul>
<li class="chapter" data-level="12.5.1" data-path="bookdown-edit.html"><a href="bookdown-edit.html#build-the-book"><i class="fa fa-check"></i><b>12.5.1</b> Build the book</a></li>
<li class="chapter" data-level="12.5.2" data-path="bookdown-edit.html"><a href="bookdown-edit.html#preview-a-chapter"><i class="fa fa-check"></i><b>12.5.2</b> Preview a chapter</a></li>
<li class="chapter" data-level="12.5.3" data-path="bookdown-edit.html"><a href="bookdown-edit.html#serve-the-book"><i class="fa fa-check"></i><b>12.5.3</b> Serve the book</a></li>
<li class="chapter" data-level="12.5.4" data-path="bookdown-edit.html"><a href="bookdown-edit.html#rstudio-addins"><i class="fa fa-check"></i><b>12.5.4</b> RStudio addins</a></li>
</ul></li>
<li class="chapter" data-level="12.6" data-path="bookdown-publish.html"><a href="bookdown-publish.html"><i class="fa fa-check"></i><b>12.6</b> Publishing</a><ul>
<li class="chapter" data-level="12.6.1" data-path="bookdown-publish.html"><a href="bookdown-publish.html#rstudio-connect"><i class="fa fa-check"></i><b>12.6.1</b> RStudio Connect</a></li>
<li class="chapter" data-level="12.6.2" data-path="bookdown-publish.html"><a href="bookdown-publish.html#other-services"><i class="fa fa-check"></i><b>12.6.2</b> Other services</a></li>
<li class="chapter" data-level="12.6.3" data-path="bookdown-publish.html"><a href="bookdown-publish.html#publishers"><i class="fa fa-check"></i><b>12.6.3</b> Publishers</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="13" data-path="journals.html"><a href="journals.html"><i class="fa fa-check"></i><b>13</b> Journals</a><ul>
<li class="chapter" data-level="13.1" data-path="rticles-start.html"><a href="rticles-start.html"><i class="fa fa-check"></i><b>13.1</b> Get started</a></li>
<li class="chapter" data-level="13.2" data-path="rticles-templates.html"><a href="rticles-templates.html"><i class="fa fa-check"></i><b>13.2</b> rticles templates</a></li>
<li class="chapter" data-level="13.3" data-path="rticles-usage.html"><a href="rticles-usage.html"><i class="fa fa-check"></i><b>13.3</b> Using a template</a></li>
<li class="chapter" data-level="13.4" data-path="rticles-latex.html"><a href="rticles-latex.html"><i class="fa fa-check"></i><b>13.4</b> LaTeX content</a></li>
<li class="chapter" data-level="13.5" data-path="rticles-bookdown.html"><a href="rticles-bookdown.html"><i class="fa fa-check"></i><b>13.5</b> Linking with bookdown</a></li>
<li class="chapter" data-level="13.6" data-path="rticles-contrib.html"><a href="rticles-contrib.html"><i class="fa fa-check"></i><b>13.6</b> Contributing templates</a></li>
</ul></li>
<li class="chapter" data-level="14" data-path="learnr.html"><a href="learnr.html"><i class="fa fa-check"></i><b>14</b> Interactive Tutorials</a><ul>
<li class="chapter" data-level="14.1" data-path="learnr-start.html"><a href="learnr-start.html"><i class="fa fa-check"></i><b>14.1</b> Get started</a></li>
<li class="chapter" data-level="14.2" data-path="learnr-types.html"><a href="learnr-types.html"><i class="fa fa-check"></i><b>14.2</b> Tutorial types</a></li>
<li class="chapter" data-level="14.3" data-path="learnr-exercises.html"><a href="learnr-exercises.html"><i class="fa fa-check"></i><b>14.3</b> Exercises</a><ul>
<li class="chapter" data-level="14.3.1" data-path="learnr-exercises.html"><a href="learnr-exercises.html#solutions"><i class="fa fa-check"></i><b>14.3.1</b> Solutions</a></li>
<li class="chapter" data-level="14.3.2" data-path="learnr-exercises.html"><a href="learnr-exercises.html#hints"><i class="fa fa-check"></i><b>14.3.2</b> Hints</a></li>
</ul></li>
<li class="chapter" data-level="14.4" data-path="learnr-quiz.html"><a href="learnr-quiz.html"><i class="fa fa-check"></i><b>14.4</b> Quiz questions</a></li>
<li class="chapter" data-level="14.5" data-path="learnr-videos.html"><a href="learnr-videos.html"><i class="fa fa-check"></i><b>14.5</b> Videos</a></li>
<li class="chapter" data-level="14.6" data-path="learnr-shiny.html"><a href="learnr-shiny.html"><i class="fa fa-check"></i><b>14.6</b> Shiny components</a></li>
<li class="chapter" data-level="14.7" data-path="learnr-nav.html"><a href="learnr-nav.html"><i class="fa fa-check"></i><b>14.7</b> Navigation and progress tracking</a></li>
</ul></li>
<li class="part"><span><b>IV Other Topics</b></span></li>
<li class="chapter" data-level="15" data-path="parameterized-reports.html"><a href="parameterized-reports.html"><i class="fa fa-check"></i><b>15</b> Parameterized reports</a><ul>
<li class="chapter" data-level="15.1" data-path="params-declare.html"><a href="params-declare.html"><i class="fa fa-check"></i><b>15.1</b> Declaring parameters</a></li>
<li class="chapter" data-level="15.2" data-path="params-use.html"><a href="params-use.html"><i class="fa fa-check"></i><b>15.2</b> Using parameters</a></li>
<li class="chapter" data-level="15.3" data-path="params-knit.html"><a href="params-knit.html"><i class="fa fa-check"></i><b>15.3</b> Knitting with parameters</a><ul>
<li class="chapter" data-level="15.3.1" data-path="params-knit.html"><a href="params-knit.html#the-knit-button"><i class="fa fa-check"></i><b>15.3.1</b> The <code>Knit</code> button</a></li>
<li class="chapter" data-level="15.3.2" data-path="params-knit.html"><a href="params-knit.html#knit-with-custom-parameters"><i class="fa fa-check"></i><b>15.3.2</b> Knit with custom parameters</a></li>
<li class="chapter" data-level="15.3.3" data-path="params-knit.html"><a href="params-knit.html#the-interactive-user-interface"><i class="fa fa-check"></i><b>15.3.3</b> The interactive user interface</a></li>
</ul></li>
<li class="chapter" data-level="15.4" data-path="params-publish.html"><a href="params-publish.html"><i class="fa fa-check"></i><b>15.4</b> Publishing</a></li>
</ul></li>
<li class="chapter" data-level="16" data-path="html-widgets.html"><a href="html-widgets.html"><i class="fa fa-check"></i><b>16</b> HTML Widgets</a><ul>
<li class="chapter" data-level="16.1" data-path="htmlwidgets-overview.html"><a href="htmlwidgets-overview.html"><i class="fa fa-check"></i><b>16.1</b> Overview</a></li>
<li class="chapter" data-level="16.2" data-path="htmlwidgets-sigma.html"><a href="htmlwidgets-sigma.html"><i class="fa fa-check"></i><b>16.2</b> A widget example (sigma.js)</a><ul>
<li class="chapter" data-level="16.2.1" data-path="htmlwidgets-sigma.html"><a href="htmlwidgets-sigma.html#file-layout"><i class="fa fa-check"></i><b>16.2.1</b> File layout</a></li>
<li class="chapter" data-level="16.2.2" data-path="htmlwidgets-sigma.html"><a href="htmlwidgets-sigma.html#dependencies"><i class="fa fa-check"></i><b>16.2.2</b> Dependencies</a></li>
<li class="chapter" data-level="16.2.3" data-path="htmlwidgets-sigma.html"><a href="htmlwidgets-sigma.html#r-binding"><i class="fa fa-check"></i><b>16.2.3</b> R binding</a></li>
<li class="chapter" data-level="16.2.4" data-path="htmlwidgets-sigma.html"><a href="htmlwidgets-sigma.html#javascript-binding"><i class="fa fa-check"></i><b>16.2.4</b> JavaScript binding</a></li>
<li class="chapter" data-level="16.2.5" data-path="htmlwidgets-sigma.html"><a href="htmlwidgets-sigma.html#demo"><i class="fa fa-check"></i><b>16.2.5</b> Demo</a></li>
</ul></li>
<li class="chapter" data-level="16.3" data-path="htmlwidgets-create.html"><a href="htmlwidgets-create.html"><i class="fa fa-check"></i><b>16.3</b> Creating your own widgets</a><ul>
<li class="chapter" data-level="16.3.1" data-path="htmlwidgets-create.html"><a href="htmlwidgets-create.html#requirements"><i class="fa fa-check"></i><b>16.3.1</b> Requirements</a></li>
<li class="chapter" data-level="16.3.2" data-path="htmlwidgets-create.html"><a href="htmlwidgets-create.html#scaffolding"><i class="fa fa-check"></i><b>16.3.2</b> Scaffolding</a></li>
<li class="chapter" data-level="16.3.3" data-path="htmlwidgets-create.html"><a href="htmlwidgets-create.html#other-packages"><i class="fa fa-check"></i><b>16.3.3</b> Other packages</a></li>
</ul></li>
<li class="chapter" data-level="16.4" data-path="htmlwidgets-size.html"><a href="htmlwidgets-size.html"><i class="fa fa-check"></i><b>16.4</b> Widget sizing</a><ul>
<li class="chapter" data-level="16.4.1" data-path="htmlwidgets-size.html"><a href="htmlwidgets-size.html#specifying-a-sizing-policy"><i class="fa fa-check"></i><b>16.4.1</b> Specifying a sizing policy</a></li>
<li class="chapter" data-level="16.4.2" data-path="htmlwidgets-size.html"><a href="htmlwidgets-size.html#javascript-resize-method"><i class="fa fa-check"></i><b>16.4.2</b> JavaScript resize method</a></li>
</ul></li>
<li class="chapter" data-level="16.5" data-path="htmlwidgets-advanced.html"><a href="htmlwidgets-advanced.html"><i class="fa fa-check"></i><b>16.5</b> Advanced topics</a><ul>
<li class="chapter" data-level="16.5.1" data-path="htmlwidgets-advanced.html"><a href="htmlwidgets-advanced.html#data-transformation"><i class="fa fa-check"></i><b>16.5.1</b> Data transformation</a></li>
<li class="chapter" data-level="16.5.2" data-path="htmlwidgets-advanced.html"><a href="htmlwidgets-advanced.html#passing-javascript-functions"><i class="fa fa-check"></i><b>16.5.2</b> Passing JavaScript functions</a></li>
<li class="chapter" data-level="16.5.3" data-path="htmlwidgets-advanced.html"><a href="htmlwidgets-advanced.html#custom-widget-html"><i class="fa fa-check"></i><b>16.5.3</b> Custom widget HTML</a></li>
<li class="chapter" data-level="16.5.4" data-path="htmlwidgets-advanced.html"><a href="htmlwidgets-advanced.html#create-a-widget-without-an-r-package"><i class="fa fa-check"></i><b>16.5.4</b> Create a widget without an R package</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="17" data-path="document-templates.html"><a href="document-templates.html"><i class="fa fa-check"></i><b>17</b> Document Templates</a><ul>
<li class="chapter" data-level="17.1" data-path="template-structure.html"><a href="template-structure.html"><i class="fa fa-check"></i><b>17.1</b> Template structure</a></li>
<li class="chapter" data-level="17.2" data-path="template-support.html"><a href="template-support.html"><i class="fa fa-check"></i><b>17.2</b> Supporting files</a></li>
<li class="chapter" data-level="17.3" data-path="template-pandoc.html"><a href="template-pandoc.html"><i class="fa fa-check"></i><b>17.3</b> Custom Pandoc templates</a></li>
<li class="chapter" data-level="17.4" data-path="template-share.html"><a href="template-share.html"><i class="fa fa-check"></i><b>17.4</b> Sharing your templates</a></li>
</ul></li>
<li class="chapter" data-level="18" data-path="new-formats.html"><a href="new-formats.html"><i class="fa fa-check"></i><b>18</b> Creating New Formats</a><ul>
<li class="chapter" data-level="18.1" data-path="format-derive.html"><a href="format-derive.html"><i class="fa fa-check"></i><b>18.1</b> Deriving from built-in formats</a></li>
<li class="chapter" data-level="18.2" data-path="format-custom.html"><a href="format-custom.html"><i class="fa fa-check"></i><b>18.2</b> Fully custom formats</a></li>
<li class="chapter" data-level="18.3" data-path="format-use.html"><a href="format-use.html"><i class="fa fa-check"></i><b>18.3</b> Using a new format</a></li>
</ul></li>
<li class="chapter" data-level="19" data-path="shiny-documents.html"><a href="shiny-documents.html"><i class="fa fa-check"></i><b>19</b> Shiny Documents</a><ul>
<li class="chapter" data-level="19.1" data-path="shiny-start.html"><a href="shiny-start.html"><i class="fa fa-check"></i><b>19.1</b> Getting started</a></li>
<li class="chapter" data-level="19.2" data-path="shiny-deploy.html"><a href="shiny-deploy.html"><i class="fa fa-check"></i><b>19.2</b> Deployment</a><ul>
<li class="chapter" data-level="19.2.1" data-path="shiny-deploy.html"><a href="shiny-deploy.html#shinyapps.io"><i class="fa fa-check"></i><b>19.2.1</b> ShinyApps.io</a></li>
<li class="chapter" data-level="19.2.2" data-path="shiny-deploy.html"><a href="shiny-deploy.html#shiny-server-rstudio-connect"><i class="fa fa-check"></i><b>19.2.2</b> Shiny Server / RStudio Connect</a></li>
</ul></li>
<li class="chapter" data-level="19.3" data-path="shiny-embedded.html"><a href="shiny-embedded.html"><i class="fa fa-check"></i><b>19.3</b> Embedded Shiny apps</a><ul>
<li class="chapter" data-level="19.3.1" data-path="shiny-embedded.html"><a href="shiny-embedded.html#shiny-embed-inline"><i class="fa fa-check"></i><b>19.3.1</b> Inline applications</a></li>
<li class="chapter" data-level="19.3.2" data-path="shiny-embedded.html"><a href="shiny-embedded.html#external-applications"><i class="fa fa-check"></i><b>19.3.2</b> External applications</a></li>
</ul></li>
<li class="chapter" data-level="19.4" data-path="shiny-widgets.html"><a href="shiny-widgets.html"><i class="fa fa-check"></i><b>19.4</b> Shiny widgets</a><ul>
<li class="chapter" data-level="19.4.1" data-path="shiny-widgets.html"><a href="shiny-widgets.html#the-shinyapp-function"><i class="fa fa-check"></i><b>19.4.1</b> The <code>shinyApp()</code> function</a></li>
<li class="chapter" data-level="19.4.2" data-path="shiny-widgets.html"><a href="shiny-widgets.html#example-k-means-clustering"><i class="fa fa-check"></i><b>19.4.2</b> Example: k-Means clustering</a></li>
<li class="chapter" data-level="19.4.3" data-path="shiny-widgets.html"><a href="shiny-widgets.html#widget-size-and-layout"><i class="fa fa-check"></i><b>19.4.3</b> Widget size and layout</a></li>
</ul></li>
<li class="chapter" data-level="19.5" data-path="shiny-multiple.html"><a href="shiny-multiple.html"><i class="fa fa-check"></i><b>19.5</b> Multiple pages</a></li>
<li class="chapter" data-level="19.6" data-path="shiny-delay.html"><a href="shiny-delay.html"><i class="fa fa-check"></i><b>19.6</b> Delayed rendering</a></li>
<li class="chapter" data-level="19.7" data-path="shiny-args.html"><a href="shiny-args.html"><i class="fa fa-check"></i><b>19.7</b> Output arguments for render functions</a><ul>
<li class="chapter" data-level="19.7.1" data-path="shiny-args.html"><a href="shiny-args.html#a-caveat"><i class="fa fa-check"></i><b>19.7.1</b> A caveat</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>References</a></li>
<li class="divider"></li>
<li><a href="https://bookdown.org" target="_blank">Published with bookdown</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">R Markdown 最佳指南</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="htmlwidgets-advanced" class="section level2">
<h2><span class="header-section-number">16.5</span> Advanced topics</h2>
<p>This section covers several aspects of creating widgets that are not required by all widgets, but are an essential part of getting bindings to certain types of JavaScript libraries to work properly. Topics covered include:</p>
<ul>
<li><p>Transforming JSON representations of R objects into representations required by JavaScript libraries (e.g., an R data frame to a D3 dataset).</p></li>
<li><p>Passing JavaScript functions from R to JavaScript (e.g., a user-provided formatting or drawing function)</p></li>
<li><p>Generating custom HTML to enclose a widget (the default is a <code>&lt;div&gt;</code>, but some libraries require a different element, e.g., a <code>&lt;span&gt;</code>).</p></li>
<li><p>Creating a widget without creating an R package in the first place.</p></li>
</ul>
<div id="data-transformation" class="section level3">
<h3><span class="header-section-number">16.5.1</span> Data transformation</h3>
<p>R objects passed as part of the <code>x</code> parameter to the <code>createWidget()</code> function are transformed to JSON using the internal function <code>htmlwidgets:::toJSON()</code><a href="#fn15" class="footnote-ref" id="fnref15"><sup>15</sup></a>, which is basically a wrapper function of <code>jsonlite::toJSON()</code> by default. However, sometimes this representation is not what is required by the JavaScript library you are interfacing with. There are two JavaScript functions that you can use to transform the JSON data.</p>
<div id="htmlwidgets.dataframetod3" class="section level4">
<h4><span class="header-section-number">16.5.1.1</span> HTMLWidgets.dataframeToD3()</h4>
<p>R data frames are represented in “long” form (an array of named vectors) whereas D3 typically requires “wide” form (an array of objects each of which includes all names and values). Since the R representation is smaller in size and much faster to transmit over the network, we create the long-form representation of R data, and then transform the data in JavaScript using the <code>dataframeToD3()</code> helper function.</p>
<p>Here is an example of the long-form representation of an R data frame:</p>
<div class="sourceCode" id="cb329"><pre class="sourceCode json"><code class="sourceCode json"><a class="sourceLine" id="cb329-1" data-line-number="1"><span class="fu">{</span></a>
<a class="sourceLine" id="cb329-2" data-line-number="2">  <span class="dt">&quot;Sepal.Length&quot;</span><span class="fu">:</span> <span class="ot">[</span><span class="fl">5.1</span><span class="ot">,</span> <span class="fl">4.9</span><span class="ot">,</span> <span class="fl">4.7</span><span class="ot">]</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb329-3" data-line-number="3">  <span class="dt">&quot;Sepal.Width&quot;</span><span class="fu">:</span> <span class="ot">[</span><span class="fl">3.5</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">,</span> <span class="fl">3.2</span><span class="ot">]</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb329-4" data-line-number="4">  <span class="dt">&quot;Petal.Length&quot;</span><span class="fu">:</span> <span class="ot">[</span><span class="fl">1.4</span><span class="ot">,</span> <span class="fl">1.4</span><span class="ot">,</span> <span class="fl">1.3</span><span class="ot">]</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb329-5" data-line-number="5">  <span class="dt">&quot;Petal.Width&quot;</span><span class="fu">:</span> <span class="ot">[</span><span class="fl">0.2</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">]</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb329-6" data-line-number="6">  <span class="dt">&quot;Species&quot;</span><span class="fu">:</span> <span class="ot">[</span><span class="st">&quot;setosa&quot;</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">]</span></a>
<a class="sourceLine" id="cb329-7" data-line-number="7"><span class="fu">}</span> </a></code></pre></div>
<p>After we apply <code>HTMLWidgets.dataframeToD3()</code>, it will become:</p>
<div class="sourceCode" id="cb330"><pre class="sourceCode json"><code class="sourceCode json"><a class="sourceLine" id="cb330-1" data-line-number="1"><span class="ot">[</span></a>
<a class="sourceLine" id="cb330-2" data-line-number="2">  <span class="fu">{</span></a>
<a class="sourceLine" id="cb330-3" data-line-number="3">    <span class="dt">&quot;Sepal.Length&quot;</span><span class="fu">:</span> <span class="fl">5.1</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-4" data-line-number="4">    <span class="dt">&quot;Sepal.Width&quot;</span><span class="fu">:</span> <span class="fl">3.5</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-5" data-line-number="5">    <span class="dt">&quot;Petal.Length&quot;</span><span class="fu">:</span> <span class="fl">1.4</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-6" data-line-number="6">    <span class="dt">&quot;Petal.Width&quot;</span><span class="fu">:</span> <span class="fl">0.2</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-7" data-line-number="7">    <span class="dt">&quot;Species&quot;</span><span class="fu">:</span> <span class="st">&quot;setosa&quot;</span></a>
<a class="sourceLine" id="cb330-8" data-line-number="8">  <span class="fu">}</span><span class="ot">,</span></a>
<a class="sourceLine" id="cb330-9" data-line-number="9">  <span class="fu">{</span></a>
<a class="sourceLine" id="cb330-10" data-line-number="10">    <span class="dt">&quot;Sepal.Length&quot;</span><span class="fu">:</span> <span class="fl">4.9</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-11" data-line-number="11">    <span class="dt">&quot;Sepal.Width&quot;</span><span class="fu">:</span> <span class="dv">3</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-12" data-line-number="12">    <span class="dt">&quot;Petal.Length&quot;</span><span class="fu">:</span> <span class="fl">1.4</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-13" data-line-number="13">    <span class="dt">&quot;Petal.Width&quot;</span><span class="fu">:</span> <span class="fl">0.2</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-14" data-line-number="14">    <span class="dt">&quot;Species&quot;</span><span class="fu">:</span> <span class="st">&quot;setosa&quot;</span></a>
<a class="sourceLine" id="cb330-15" data-line-number="15">  <span class="fu">}</span><span class="ot">,</span></a>
<a class="sourceLine" id="cb330-16" data-line-number="16">  <span class="fu">{</span></a>
<a class="sourceLine" id="cb330-17" data-line-number="17">    <span class="dt">&quot;Sepal.Length&quot;</span><span class="fu">:</span> <span class="fl">4.7</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-18" data-line-number="18">    <span class="dt">&quot;Sepal.Width&quot;</span><span class="fu">:</span> <span class="fl">3.2</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-19" data-line-number="19">    <span class="dt">&quot;Petal.Length&quot;</span><span class="fu">:</span> <span class="fl">1.3</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-20" data-line-number="20">    <span class="dt">&quot;Petal.Width&quot;</span><span class="fu">:</span> <span class="fl">0.2</span><span class="fu">,</span></a>
<a class="sourceLine" id="cb330-21" data-line-number="21">    <span class="dt">&quot;Species&quot;</span><span class="fu">:</span> <span class="st">&quot;setosa&quot;</span></a>
<a class="sourceLine" id="cb330-22" data-line-number="22">  <span class="fu">}</span></a>
<a class="sourceLine" id="cb330-23" data-line-number="23"><span class="ot">]</span> </a></code></pre></div>
<p>As a real example, the <code>simpleNetwork</code> (<a href="https://christophergandrud.github.io/networkD3/#simple" class="uri">https://christophergandrud.github.io/networkD3/#simple</a>) widget accepts a data frame containing network links on the R side, and transforms it to a D3 representation within the JavaScript <code>renderValue</code> function:</p>
<div class="sourceCode" id="cb331"><pre class="sourceCode js"><code class="sourceCode javascript"><a class="sourceLine" id="cb331-1" data-line-number="1">renderValue<span class="op">:</span> <span class="kw">function</span>(x) <span class="op">{</span></a>
<a class="sourceLine" id="cb331-2" data-line-number="2"></a>
<a class="sourceLine" id="cb331-3" data-line-number="3">  <span class="co">// convert links data frame to d3 friendly format</span></a>
<a class="sourceLine" id="cb331-4" data-line-number="4">  <span class="kw">var</span> links <span class="op">=</span> <span class="va">HTMLWidgets</span>.<span class="at">dataframeToD3</span>(<span class="va">x</span>.<span class="at">links</span>)<span class="op">;</span></a>
<a class="sourceLine" id="cb331-5" data-line-number="5"></a>
<a class="sourceLine" id="cb331-6" data-line-number="6">  <span class="co">// ... use the links, etc ...</span></a>
<a class="sourceLine" id="cb331-7" data-line-number="7"></a>
<a class="sourceLine" id="cb331-8" data-line-number="8"><span class="op">}</span></a></code></pre></div>
</div>
<div id="htmlwidgets.transposearray2d" class="section level4">
<h4><span class="header-section-number">16.5.1.2</span> HTMLWidgets.transposeArray2D()</h4>
<p>Sometimes a 2-dimensional array requires a similar transposition. For this the <code>transposeArray2D()</code> function is provided. Here is an example array:</p>
<div class="sourceCode" id="cb332"><pre class="sourceCode json"><code class="sourceCode json"><a class="sourceLine" id="cb332-1" data-line-number="1"><span class="ot">[</span></a>
<a class="sourceLine" id="cb332-2" data-line-number="2">  <span class="ot">[</span><span class="fl">5.1</span><span class="ot">,</span> <span class="fl">4.9</span><span class="ot">,</span> <span class="fl">4.7</span><span class="ot">,</span> <span class="fl">4.6</span><span class="ot">,</span> <span class="dv">5</span><span class="ot">,</span> <span class="fl">5.4</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb332-3" data-line-number="3">  <span class="ot">[</span><span class="fl">3.5</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">,</span> <span class="fl">3.2</span><span class="ot">,</span> <span class="fl">3.1</span><span class="ot">,</span> <span class="fl">3.6</span><span class="ot">,</span> <span class="fl">3.9</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb332-4" data-line-number="4">  <span class="ot">[</span><span class="fl">1.4</span><span class="ot">,</span> <span class="fl">1.4</span><span class="ot">,</span> <span class="fl">1.3</span><span class="ot">,</span> <span class="fl">1.5</span><span class="ot">,</span> <span class="fl">1.4</span><span class="ot">,</span> <span class="fl">1.7</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb332-5" data-line-number="5">  <span class="ot">[</span><span class="fl">0.2</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="fl">0.4</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb332-6" data-line-number="6">  <span class="ot">[</span><span class="st">&quot;setosa&quot;</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">]</span></a>
<a class="sourceLine" id="cb332-7" data-line-number="7"><span class="ot">]</span> </a></code></pre></div>
<p><code>HTMLWidgets.transposeArray2D()</code> can transpose it to:</p>
<div class="sourceCode" id="cb333"><pre class="sourceCode json"><code class="sourceCode json"><a class="sourceLine" id="cb333-1" data-line-number="1"><span class="ot">[</span></a>
<a class="sourceLine" id="cb333-2" data-line-number="2">  <span class="ot">[</span><span class="fl">5.1</span><span class="ot">,</span> <span class="fl">3.5</span><span class="ot">,</span> <span class="fl">1.4</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb333-3" data-line-number="3">  <span class="ot">[</span><span class="fl">4.9</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">,</span> <span class="fl">1.4</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb333-4" data-line-number="4">  <span class="ot">[</span><span class="fl">4.7</span><span class="ot">,</span> <span class="fl">3.2</span><span class="ot">,</span> <span class="fl">1.3</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb333-5" data-line-number="5">  <span class="ot">[</span><span class="fl">4.6</span><span class="ot">,</span> <span class="fl">3.1</span><span class="ot">,</span> <span class="fl">1.5</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb333-6" data-line-number="6">  <span class="ot">[</span><span class="dv">5</span><span class="ot">,</span> <span class="fl">3.6</span><span class="ot">,</span> <span class="fl">1.4</span><span class="ot">,</span> <span class="fl">0.2</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">],</span></a>
<a class="sourceLine" id="cb333-7" data-line-number="7">  <span class="ot">[</span><span class="fl">5.4</span><span class="ot">,</span> <span class="fl">3.9</span><span class="ot">,</span> <span class="fl">1.7</span><span class="ot">,</span> <span class="fl">0.4</span><span class="ot">,</span> <span class="st">&quot;setosa&quot;</span><span class="ot">]</span></a>
<a class="sourceLine" id="cb333-8" data-line-number="8"><span class="ot">]</span> </a></code></pre></div>
<p>As a real example, the <a href="https://rstudio.github.io/dygraphs">dygraphs</a> widget uses this function to transpose the “file” (data) argument it gets from the R side before passing it on to the dygraphs library:</p>
<div class="sourceCode" id="cb334"><pre class="sourceCode javascript"><code class="sourceCode javascript"><a class="sourceLine" id="cb334-1" data-line-number="1">renderValue<span class="op">:</span> <span class="kw">function</span>(x) <span class="op">{</span></a>
<a class="sourceLine" id="cb334-2" data-line-number="2"></a>
<a class="sourceLine" id="cb334-3" data-line-number="3">    <span class="co">// ... code excluded ...</span></a>
<a class="sourceLine" id="cb334-4" data-line-number="4"></a>
<a class="sourceLine" id="cb334-5" data-line-number="5">    <span class="co">// transpose array</span></a>
<a class="sourceLine" id="cb334-6" data-line-number="6">    <span class="va">x</span>.<span class="va">attrs</span>.<span class="at">file</span> <span class="op">=</span> <span class="va">HTMLWidgets</span>.<span class="at">transposeArray2D</span>(<span class="va">x</span>.<span class="va">attrs</span>.<span class="at">file</span>)<span class="op">;</span></a>
<a class="sourceLine" id="cb334-7" data-line-number="7"></a>
<a class="sourceLine" id="cb334-8" data-line-number="8">    <span class="co">// ... more code excluded ...</span></a>
<a class="sourceLine" id="cb334-9" data-line-number="9"><span class="op">}</span></a></code></pre></div>
</div>
<div id="custom-json-serializer" class="section level4">
<h4><span class="header-section-number">16.5.1.3</span> Custom JSON serializer</h4>
<p>You may find it necessary to customize the JSON serialization of widget data when the default serializer in <strong>htmlwidgets</strong> does not work in the way you have expected. For widget package authors, there are two levels of customization for the JSON serialization: you can either customize the default values of arguments for <code>jsonlite::toJSON()</code>, or just customize the whole function.</p>
<ol style="list-style-type: decimal">
<li><p><code>jsonlite::toJSON()</code> has a lot of arguments, and we have already changed some of its default values. Below is the JSON serializer we use in <strong>htmlwidgets</strong> at the moment:</p>
<div class="sourceCode" id="cb335"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb335-1" data-line-number="1"><span class="cf">function</span> (x, ..., <span class="dt">dataframe =</span> <span class="st">&quot;columns&quot;</span>, <span class="dt">null =</span> <span class="st">&quot;null&quot;</span>, <span class="dt">na =</span> <span class="st">&quot;null&quot;</span>, </a>
<a class="sourceLine" id="cb335-2" data-line-number="2">    <span class="dt">auto_unbox =</span> <span class="ot">TRUE</span>, <span class="dt">digits =</span> <span class="kw">getOption</span>(<span class="st">&quot;shiny.json.digits&quot;</span>, </a>
<a class="sourceLine" id="cb335-3" data-line-number="3">        <span class="dv">16</span>), <span class="dt">use_signif =</span> <span class="ot">TRUE</span>, <span class="dt">force =</span> <span class="ot">TRUE</span>, <span class="dt">POSIXt =</span> <span class="st">&quot;ISO8601&quot;</span>, </a>
<a class="sourceLine" id="cb335-4" data-line-number="4">    <span class="dt">UTC =</span> <span class="ot">TRUE</span>, <span class="dt">rownames =</span> <span class="ot">FALSE</span>, <span class="dt">keep_vec_names =</span> <span class="ot">TRUE</span>, <span class="dt">strict_atomic =</span> <span class="ot">TRUE</span>) </a>
<a class="sourceLine" id="cb335-5" data-line-number="5">{</a>
<a class="sourceLine" id="cb335-6" data-line-number="6">    <span class="cf">if</span> (strict_atomic) </a>
<a class="sourceLine" id="cb335-7" data-line-number="7">        x &lt;-<span class="st"> </span><span class="kw">I</span>(x)</a>
<a class="sourceLine" id="cb335-8" data-line-number="8">    jsonlite<span class="op">::</span><span class="kw">toJSON</span>(x, <span class="dt">dataframe =</span> dataframe, <span class="dt">null =</span> null, <span class="dt">na =</span> na, </a>
<a class="sourceLine" id="cb335-9" data-line-number="9">        <span class="dt">auto_unbox =</span> auto_unbox, <span class="dt">digits =</span> digits, <span class="dt">use_signif =</span> use_signif, </a>
<a class="sourceLine" id="cb335-10" data-line-number="10">        <span class="dt">force =</span> force, <span class="dt">POSIXt =</span> POSIXt, <span class="dt">UTC =</span> UTC, <span class="dt">rownames =</span> rownames, </a>
<a class="sourceLine" id="cb335-11" data-line-number="11">        <span class="dt">keep_vec_names =</span> keep_vec_names, <span class="dt">json_verbatim =</span> <span class="ot">TRUE</span>, </a>
<a class="sourceLine" id="cb335-12" data-line-number="12">        ...)</a>
<a class="sourceLine" id="cb335-13" data-line-number="13">}</a></code></pre></div>
<p>For example, we convert data frames to JSON by columns instead of rows (the latter is <code>jsonlite::toJSON</code>’s default). If you want to change the default values of any arguments, you can attach an attribute <code>TOJSON_ARGS</code> to the widget data to be passed to <code>createWidget()</code>, e.g.,</p>
<div class="sourceCode" id="cb336"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb336-1" data-line-number="1">fooWidget =<span class="st"> </span><span class="cf">function</span>(data, name, ...) {</a>
<a class="sourceLine" id="cb336-2" data-line-number="2">  <span class="co"># ... process the data ...</span></a>
<a class="sourceLine" id="cb336-3" data-line-number="3">  params =<span class="st"> </span><span class="kw">list</span>(<span class="dt">foo =</span> data, <span class="dt">bar =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb336-4" data-line-number="4">  <span class="co"># customize toJSON() argument values</span></a>
<a class="sourceLine" id="cb336-5" data-line-number="5">  <span class="kw">attr</span>(params, <span class="st">&#39;TOJSON_ARGS&#39;</span>) =<span class="st"> </span><span class="kw">list</span>(</a>
<a class="sourceLine" id="cb336-6" data-line-number="6">    <span class="dt">digits =</span> <span class="dv">7</span>, <span class="dt">na =</span> <span class="st">&#39;string&#39;</span></a>
<a class="sourceLine" id="cb336-7" data-line-number="7">  )</a>
<a class="sourceLine" id="cb336-8" data-line-number="8">  htmlwidgets<span class="op">::</span><span class="kw">createWidget</span>(name, <span class="dt">x =</span> params, ...)</a>
<a class="sourceLine" id="cb336-9" data-line-number="9">}</a></code></pre></div>
<p>We changed the default value of <code>digits</code> from 16 to 7, and <code>na</code> from <code>null</code> to <code>string</code> in the above example. It is up to you, the package author, whether you want to expose such customization to users. For example, you can leave an extra argument in your widget function so that users can customize the behavior of the JSON serializer:</p>
<div class="sourceCode" id="cb337"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb337-1" data-line-number="1">fooWidget =<span class="st"> </span><span class="cf">function</span>(</a>
<a class="sourceLine" id="cb337-2" data-line-number="2">  data, name, ..., <span class="dt">JSONArgs =</span> <span class="kw">list</span>(<span class="dt">digits =</span> <span class="dv">7</span>)</a>
<a class="sourceLine" id="cb337-3" data-line-number="3">) {</a>
<a class="sourceLine" id="cb337-4" data-line-number="4">  <span class="co"># ... process the data ...</span></a>
<a class="sourceLine" id="cb337-5" data-line-number="5">  params =<span class="st"> </span><span class="kw">list</span>(<span class="dt">foo =</span> data, <span class="dt">bar =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb337-6" data-line-number="6">  <span class="co"># customize toJSON() argument values</span></a>
<a class="sourceLine" id="cb337-7" data-line-number="7">  <span class="kw">attr</span>(params, <span class="st">&#39;TOJSON_ARGS&#39;</span>) =<span class="st"> </span>JSONArgs</a>
<a class="sourceLine" id="cb337-8" data-line-number="8">  htmlwidgets<span class="op">::</span><span class="kw">createWidget</span>(name, <span class="dt">x =</span> params, ...)</a>
<a class="sourceLine" id="cb337-9" data-line-number="9">}</a></code></pre></div>
<p>You can also use a global option <code>htmlwidgets.TOJSON_ARGS</code> to customize the JSON serializer arguments for all widgets in the current R session, e.g.</p>
<div class="sourceCode" id="cb338"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb338-1" data-line-number="1"><span class="kw">options</span>(<span class="dt">htmlwidgets.TOJSON_ARGS =</span> <span class="kw">list</span>(</a>
<a class="sourceLine" id="cb338-2" data-line-number="2">  <span class="dt">digits =</span> <span class="dv">7</span>, <span class="dt">pretty =</span> <span class="ot">TRUE</span></a>
<a class="sourceLine" id="cb338-3" data-line-number="3">))</a></code></pre></div></li>
<li><p>If you do not want to use <strong>jsonlite</strong>, you can completely override the serializer function by attaching an attribute <code>TOJSON_FUNC</code> to the widget data, e.g.,</p>
<div class="sourceCode" id="cb339"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb339-1" data-line-number="1">fooWidget =<span class="st"> </span><span class="cf">function</span>(data, name, ...) {</a>
<a class="sourceLine" id="cb339-2" data-line-number="2">  <span class="co"># ... process the data ...</span></a>
<a class="sourceLine" id="cb339-3" data-line-number="3">  params =<span class="st"> </span><span class="kw">list</span>(<span class="dt">foo =</span> data, <span class="dt">bar =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb339-4" data-line-number="4">  <span class="co"># customize the JSON serializer</span></a>
<a class="sourceLine" id="cb339-5" data-line-number="5">  <span class="kw">attr</span>(params, <span class="st">&#39;TOJSON_FUNC&#39;</span>) =<span class="st"> </span>MY_OWN_JSON_FUNCTION</a>
<a class="sourceLine" id="cb339-6" data-line-number="6">  htmlwidgets<span class="op">::</span><span class="kw">createWidget</span>(name, <span class="dt">x =</span> params, ...)</a>
<a class="sourceLine" id="cb339-7" data-line-number="7">}</a></code></pre></div>
<p>Here <code>MY_OWN_JSON_FUNCTION</code> can be an arbitrary R function that converts R objects to JSON. If you have also specified the <code>TOJSON_ARGS</code> attribute, it will be passed to your custom JSON function, too.</p></li>
</ol>
</div>
</div>
<div id="passing-javascript-functions" class="section level3">
<h3><span class="header-section-number">16.5.2</span> Passing JavaScript functions</h3>
<p>As you would expect, character vectors passed from R to JavaScript are converted to JavaScript strings. However, what if you want to allow users to provide custom JavaScript functions for formatting, drawing, or event handling? For this case, the <strong>htmlwidgets</strong> package includes a <code>JS()</code> function that allows you to request that a character value is evaluated as JavaScript when it is received on the client.</p>
<p>For example, the <code>dygraphs</code> widget (<a href="https://rstudio.github.io/dygraphs" class="uri">https://rstudio.github.io/dygraphs</a>) includes a <code>dyCallbacks</code> function that allows the user to provide callback functions for a variety of contexts. These callbacks are “marked” as containing JavaScript so that they can be converted to actual JavaScript functions on the client:</p>
<div class="sourceCode" id="cb340"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb340-1" data-line-number="1"><span class="kw">library</span>(dygraphs)</a>
<a class="sourceLine" id="cb340-2" data-line-number="2"><span class="kw">dyCallbacks</span>(</a>
<a class="sourceLine" id="cb340-3" data-line-number="3">  <span class="dt">clickCallback =</span> <span class="kw">JS</span>(...)</a>
<a class="sourceLine" id="cb340-4" data-line-number="4">  <span class="dt">drawCallback =</span> <span class="kw">JS</span>(...)</a>
<a class="sourceLine" id="cb340-5" data-line-number="5">  <span class="dt">highlightCallback =</span> <span class="kw">JS</span>(...)</a>
<a class="sourceLine" id="cb340-6" data-line-number="6">  <span class="dt">pointClickCallback =</span> <span class="kw">JS</span>(...)</a>
<a class="sourceLine" id="cb340-7" data-line-number="7">  <span class="dt">underlayCallback =</span> <span class="kw">JS</span>(...)</a>
<a class="sourceLine" id="cb340-8" data-line-number="8">)</a></code></pre></div>
<p>Another example is in the <code>DT</code> (DataTables) widget (<a href="https://rstudio.github.io/DT" class="uri">https://rstudio.github.io/DT</a>), where users can specify an <code>initComplete</code> with JavaScript to execute after the table is loaded and initialized:</p>
<div class="sourceCode" id="cb341"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb341-1" data-line-number="1"><span class="kw">datatable</span>(<span class="kw">head</span>(iris, <span class="dv">20</span>), <span class="dt">options =</span> <span class="kw">list</span>(</a>
<a class="sourceLine" id="cb341-2" data-line-number="2">  <span class="dt">initComplete =</span> <span class="kw">JS</span>(</a>
<a class="sourceLine" id="cb341-3" data-line-number="3">    <span class="st">&quot;function(settings, json) {&quot;</span>,</a>
<a class="sourceLine" id="cb341-4" data-line-number="4">    <span class="st">&quot;$(this.api().table().header()).css({</span></a>
<a class="sourceLine" id="cb341-5" data-line-number="5"><span class="st">      &#39;background-color&#39;: &#39;#000&#39;,</span></a>
<a class="sourceLine" id="cb341-6" data-line-number="6"><span class="st">      &#39;color&#39;: &#39;#fff&#39;</span></a>
<a class="sourceLine" id="cb341-7" data-line-number="7"><span class="st">     });&quot;</span>,</a>
<a class="sourceLine" id="cb341-8" data-line-number="8">    <span class="st">&quot;}&quot;</span>)</a>
<a class="sourceLine" id="cb341-9" data-line-number="9">))</a></code></pre></div>
<p>If multiple arguments are passed to <code>JS()</code> (as in the above example), they will be concatenated into a single string separated by <code>\n</code>.</p>
</div>
<div id="custom-widget-html" class="section level3">
<h3><span class="header-section-number">16.5.3</span> Custom widget HTML</h3>
<p>Typically the HTML “housing” for a widget is just a <code>&lt;div&gt;</code> element, and this is correspondingly the default behavior for new widgets that do not specify otherwise. However, sometimes you need a different element type. For example, the <code>sparkline</code> widget (<a href="https://github.com/htmlwidgets/sparkline" class="uri">https://github.com/htmlwidgets/sparkline</a>) requires a <code>&lt;span&gt;</code> element, so it implements the following custom HTML generation function:</p>
<div class="sourceCode" id="cb342"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb342-1" data-line-number="1">sparkline_html =<span class="st"> </span><span class="cf">function</span>(id, style, class, ...){</a>
<a class="sourceLine" id="cb342-2" data-line-number="2">  htmltools<span class="op">::</span>tags<span class="op">$</span><span class="kw">span</span>(<span class="dt">id =</span> id, <span class="dt">class =</span> class)</a>
<a class="sourceLine" id="cb342-3" data-line-number="3">}</a></code></pre></div>
<p>Note that this function is looked up within the package implementing the widget by the convention <code>widgetname_html</code>, so it need not be formally exported from your package or otherwise registered with <strong>htmlwidgets</strong>.</p>
<p>Most widgets will not need a custom HTML function, but if you need to generate custom HTML for your widget (e.g., you need an <code>&lt;input&gt;</code> or a <code>&lt;span&gt;</code> rather than a <code>&lt;div&gt;</code>), you should use the <strong>htmltools</strong> package (as demonstrated by the code above).</p>
</div>
<div id="create-a-widget-without-an-r-package" class="section level3">
<h3><span class="header-section-number">16.5.4</span> Create a widget without an R package</h3>
<p>As we mentioned in Section <a href="htmlwidgets-create.html#htmlwidgets-create">16.3</a>, it is possible to create a widget without creating an R package in the first place. Below is an example:</p>
<div class="sourceCode" id="cb343"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb343-1" data-line-number="1"><span class="co">#&#39; @param text A character string.</span></a>
<a class="sourceLine" id="cb343-2" data-line-number="2"><span class="co">#&#39; @param interval A time interval (in seconds).</span></a>
<a class="sourceLine" id="cb343-3" data-line-number="3">blink =<span class="st"> </span><span class="cf">function</span>(text, <span class="dt">interval =</span> <span class="dv">1</span>) {</a>
<a class="sourceLine" id="cb343-4" data-line-number="4">  htmlwidgets<span class="op">::</span><span class="kw">createWidget</span>(</a>
<a class="sourceLine" id="cb343-5" data-line-number="5">    <span class="st">&#39;blink&#39;</span>, <span class="kw">list</span>(<span class="dt">text =</span> text, <span class="dt">interval =</span> interval),</a>
<a class="sourceLine" id="cb343-6" data-line-number="6">    <span class="dt">dependencies =</span> htmltools<span class="op">::</span><span class="kw">htmlDependency</span>(</a>
<a class="sourceLine" id="cb343-7" data-line-number="7">      <span class="st">&#39;blink&#39;</span>, <span class="st">&#39;0.1&#39;</span>, <span class="dt">src =</span> <span class="kw">c</span>(<span class="dt">href =</span> <span class="st">&#39;&#39;</span>), <span class="dt">head =</span> <span class="st">&#39;</span></a>
<a class="sourceLine" id="cb343-8" data-line-number="8"><span class="st">&lt;script&gt;</span></a>
<a class="sourceLine" id="cb343-9" data-line-number="9"><span class="st">HTMLWidgets.widget({</span></a>
<a class="sourceLine" id="cb343-10" data-line-number="10"><span class="st">  name: &quot;blink&quot;,</span></a>
<a class="sourceLine" id="cb343-11" data-line-number="11"><span class="st">  type: &quot;output&quot;,</span></a>
<a class="sourceLine" id="cb343-12" data-line-number="12"><span class="st">  factory: function(el, width, height) {</span></a>
<a class="sourceLine" id="cb343-13" data-line-number="13"><span class="st">    return {</span></a>
<a class="sourceLine" id="cb343-14" data-line-number="14"><span class="st">      renderValue: function(x) {</span></a>
<a class="sourceLine" id="cb343-15" data-line-number="15"><span class="st">        setInterval(function() {</span></a>
<a class="sourceLine" id="cb343-16" data-line-number="16"><span class="st">          el.innerText = el.innerText == &quot;&quot; ? x.text : &quot;&quot;;</span></a>
<a class="sourceLine" id="cb343-17" data-line-number="17"><span class="st">        }, x.interval * 1000);</span></a>
<a class="sourceLine" id="cb343-18" data-line-number="18"><span class="st">      },</span></a>
<a class="sourceLine" id="cb343-19" data-line-number="19"><span class="st">      resize: function(width, height) {}</span></a>
<a class="sourceLine" id="cb343-20" data-line-number="20"><span class="st">    };</span></a>
<a class="sourceLine" id="cb343-21" data-line-number="21"><span class="st">  }</span></a>
<a class="sourceLine" id="cb343-22" data-line-number="22"><span class="st">});</span></a>
<a class="sourceLine" id="cb343-23" data-line-number="23"><span class="st">&lt;/script&gt;&#39;</span></a>
<a class="sourceLine" id="cb343-24" data-line-number="24">    )</a>
<a class="sourceLine" id="cb343-25" data-line-number="25">  )</a>
<a class="sourceLine" id="cb343-26" data-line-number="26">}</a>
<a class="sourceLine" id="cb343-27" data-line-number="27"></a>
<a class="sourceLine" id="cb343-28" data-line-number="28"><span class="kw">blink</span>(<span class="st">&#39;Hello htmlwidgets!&#39;</span>, <span class="fl">.5</span>)</a></code></pre></div>
<p>The widget simply shows a blinking character string, and you can specify the time interval. The key of the implementation is the HTML dependency, in which we used the <code>head</code> argument to embed the JavaScript binding. The value of the <code>src</code> argument is a little hackish due to the current restrictions in <strong>htmltools</strong> (which might be removed in the future). In the <code>renderValue</code> method, we show or hide the text periodically using the JavaScript function <code>setInterval()</code>.</p>

</div>
</div>
<!-- </div> -->
<div class="footnotes">
<hr />
<ol start="15">
<li id="fn15"><p>Note that it is not exported from <strong>htmlwidgets</strong>, so you are not supposed to call this function directly.<a href="htmlwidgets-advanced.html#fnref15" class="footnote-back">↩</a></p></li>
</ol>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="htmlwidgets-size.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="document-templates.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook/js/app.min.js"></script>
<script src="libs/gitbook/js/lunr.js"></script>
<script src="libs/gitbook/js/clipboard.min.js"></script>
<script src="libs/gitbook/js/plugin-search.js"></script>
<script src="libs/gitbook/js/plugin-sharing.js"></script>
<script src="libs/gitbook/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook/js/plugin-bookdown.js"></script>
<script src="libs/gitbook/js/jquery.highlight.js"></script>
<script src="libs/gitbook/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": true,
"facebook": false,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/ShixiangWang/rmarkdown-book/zh/edit/master/16-widgets.Rmd",
"text": "编辑"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": null,
"toc": {
"collapse": "none"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
